$(function(){ 
	init();
}); 

function init(){
	$("#queryBtn").on('click',function(){
		var username = $("#username").val();
		if(username == ''){
   		 	layer.msg("请输入您要查找的用户名！", {icon: 5});
   		 	return false;
		}else{
			$.ajax({
			   	 	type : "post",
			        url : "/TeaCulture/findfriend/check",
			        data : { "username" : username  },
			        dataType : "json",
			        traditional : true,
			        success : function(result){
			       	 if (result.result.code === "1") {
			       		 if(result.count == 0){
					   		 layer.msg("此用户名不存在,请检查后重新输入！", {icon: 5});
					   		 return false;
			       		 }else{
			       			 window.location.href="/TeaCulture/findfriend/do?username="+username;
			       		 }
			       	 }else{
				   		 layer.msg(result.result.des, {icon: 5});
				   		 return false;
			       	 }
			       },   
			       error : function(result){
			   		 	layer.msg(result.result.des, {icon: 5});
			   		 	return false;
			       }
			});
		}
	});
	

	
}
function find(sequence){
		window.location.href="/TeaCulture/findfriend/do?sequence="+sequence;
}

function add(sequence){
	var usersequence = $("#usersequence").val();
	
	
	layer.prompt({
		  title: "请输入您要添加好友的备注", //提示框标题
		},function(remark, index, elem){
		  layer.close(index);
		  if (remark != "")//如果返回的有内容  
		    {  
	        	layer.msg("添加备注成功：" + remark, {icon: 6});
		    }
		  layer.prompt({
			  title: "请输入您要发送的申请信息", //提示框标题
			},function(message, index, elem){
			  layer.close(index);
			  if (message == "")//如果返回的有内容  
			    {  
			 		 layer.msg("请输入您要发送的申请信息", {icon: 5});
			 		 return false;
			    }
   
		   $.ajax({
			   	 type : "post",
			        url : "/TeaCulture/findfriend/addUser",
			        data : { "usersequence" : usersequence, "sequence" : sequence, "remark" : remark,  "message" : message},
			        dataType : "json",
			        traditional : true,
			        success : function(result){
				       	 if(result.result.code === "1"){
					   		 layer.msg("发送申请成功", {icon: 6});
				       	 }else{
					   		 layer.msg(result.result.des, {icon: 5});
				       	 }
			       },    
			       error : function(result){
				   		 layer.msg(result.result.des, {icon: 5});
			       }
			   });
	   
		});	   
	});
}

